// miniprogram/pages/ShopAdmin/EvaluationManagement/EvaluationManagement.js
const db=wx.cloud.database()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: "好",
    Evaluate:[],
    num: 4,//后端给的分数,显示相应的星星
    one_1: 0,
    two_1: 5,
  },
  return:function(){
    wx.navigateBack({
      delta: 1
    })
  },
  // 点击tab切换
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.getEvaluate(e.target.dataset.current)
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getEvaluate(this.data.currentTab)
  },
  //获取当前时间
  // getNowDatTime:function(){
  //   var date = new Date();
  //   var seperator1 = "-";
  //   var seperator2 = ":";
  //   var month = date.getMonth() + 1;
  //   var strDate = date.getDate();
  //   if (month >= 1 && month <= 9) {
  //     month = "0" + month;
  //   }
  //   if (strDate >= 0 && strDate<=9) {
  //     strDate = "0" + strDate;
  //   }
  //   var time = date.getFullYear() + seperator1 + month + seperator1 + strDate
  //   console.log(time);
  //   return time;
  // },
  getEvaluate:function(state){
    var that=this
    that.setData({
      Evaluate:[]
    })
    wx.showLoading({
      title: '加载中',
    })
    wx.cloud.callFunction({
      name: "login",
    }).then(res => {
      console.log(res.result.openid);
      db.collection('Evaluate').where({
        state:state,
        SellOpenid:res.result.openid
      }).get().then(res => {
        // res.data 包含该记录的数据
        console.log(res.data)
        for(let i=0;i<res.data.length;i++){
          var id = "Evaluate[" + i + "].id"
          var openid = "Evaluate[" + i + "].openid"
          var avatarUrl = "Evaluate[" + i + "].avatarUrl"
          var nickName = "Evaluate[" + i + "].nickName"
          var title = "Evaluate[" + i + "].title"
          var GoodsImg = "Evaluate[" + i + "].GoodsImg"
          var GoodsRmb = "Evaluate[" + i + "].GoodsRmb"
          var GoodsTitle = "Evaluate[" + i + "].GoodsTitle"
          var OrderRmb = "Evaluate[" + i + "].OrderRmb"
          var OrderSize = "Evaluate[" + i + "].OrderSize"
          var OrderColor = "Evaluate[" + i + "].OrderColor"
          var OrderNumber = "Evaluate[" + i + "].OrderNumber"
          var img = "Evaluate[" + i + "].img"
          var one_1 = "Evaluate[" + i + "].one_1"
          var one_2 = "Evaluate[" + i + "].one_2"
          var one_3 = "Evaluate[" + i + "].one_3"
          var OrderId = "Evaluate[" + i + "].OrderId"
          var SellOpenid = "Evaluate[" + i + "].SellOpenid"
          var state = "Evaluate[" + i + "].state"
          var EvaluationTime = "Evaluate[" + i + "].EvaluationTime"
          var GoodsId = "Evaluate[" + i + "].GoodsId"
          that.setData({
            [id] :res.data[i]._id,
            [openid]:res.data[i]._openid,
            [avatarUrl]:res.data[i].avatarUrl,
            [nickName]:res.data[i].nickName,
            [title]:res.data[i].title,
            [GoodsImg]:res.data[i].GoodsImg,
            [GoodsRmb]:res.data[i].GoodsRmb,
            [GoodsTitle]:res.data[i].GoodsTitle,
            [OrderRmb]:res.data[i].OrderRmb,
            [OrderSize]:res.data[i].OrderSize,
            [OrderColor]:res.data[i].OrderColor,
            [OrderNumber]:res.data[i].OrderNumber,
            [img]:res.data[i].img,
            [one_1]:res.data[i].one_1,
            [one_2]:res.data[i].one_2,
            [one_3]:res.data[i].one_3,
            [OrderId]:res.data[i].OrderId,
            [SellOpenid]:res.data[i].SellOpenid,
            [state]:res.data[i].state,
            [EvaluationTime]:res.data[i].EvaluationTime,
            [GoodsId]:res.data[i].GoodsId,
          })
          console.log(that.data.Evaluate[i].img)
        }
        wx.hideLoading();
      })

    }).catch(err => {
      console.log(err);
      wx.hideLoading();
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})